package com.mt.channel.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.channel.entity.ChannelApplyDropCourseEntity;
import com.mt.channel.mapper.ChannelApplyDropCourseEntityMapper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;

@Component
public class ChannelApplyDropCourseModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ChannelApplyDropCourseModel.class);

    @Autowired ChannelApplyDropCourseEntityMapper channelApplyDropCourseEntityMapper;

    public ServiceResult<List<ChannelApplyDropCourseEntity>> selectList(Map<String, Object> params,
        PagerInfo<?> pagerInfo) {
        Assert.notNull(this.channelApplyDropCourseEntityMapper,
            "Property 'channelApplyDropCourseEntityMapper' is required.");
        ServiceResult<List<ChannelApplyDropCourseEntity>> result =
            new ServiceResult<List<ChannelApplyDropCourseEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }
            result.setResult(this.channelApplyDropCourseEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelApplyDropCourseModel][selectList]：query selectList occur exception", e);
        }
        return result;
    }

    public ServiceResult<ChannelApplyDropCourseEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.channelApplyDropCourseEntityMapper,
            "Property 'channelApplyDropCourseEntityMapper' is required.");
        ServiceResult<ChannelApplyDropCourseEntity> result = new ServiceResult<ChannelApplyDropCourseEntity>();
        try {
            result.setResult(this.channelApplyDropCourseEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelCoursePriceServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> insert(ChannelApplyDropCourseEntity channelApplyDropCourseEntity) {
        Assert.notNull(this.channelApplyDropCourseEntityMapper,
            "Property 'channelApplyDropCourseEntityMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save = this.channelApplyDropCourseEntityMapper.insert(channelApplyDropCourseEntity);
            if (save > 0) {
                id = channelApplyDropCourseEntity.getChannelApplyDropCourseId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelApplyDropCourseModel][insert]：query insert occur exception", e);
        }
        return result;
    }

    public ServiceResult<Integer> updateRelate(ChannelApplyDropCourseEntity channelApplyDropCourseEntity) {
        Assert.notNull(this.channelApplyDropCourseEntityMapper, "Property 'channelMenuMapper' is required.");
        ServiceResult<Integer> result = new ServiceResult<Integer>();
        int id = 0;
        try {
            int save =
                this.channelApplyDropCourseEntityMapper.updateByPrimaryKeySelective(channelApplyDropCourseEntity);
            if (save > 0) {
                id = channelApplyDropCourseEntity.getChannelApplyDropCourseId();
            }
            result.setResult(id);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[ChannelApplyDropCourseModel][updateByPrimaryKeySelective]:query update occur exception", e);
        }
        return result;
    }

}
